package ${package.Controller};

import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import com.example.cloud.entities.utils.PageQuery;
import com.example.cloud.entities.utils.SimpleMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>


/**
 * <p>
 * ${table.comment!} 内部接口
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Api(tags = "${table.comment!} 内部接口")
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    @Autowired
    public ${table.serviceName} ${table.entityPath}Service;

    /**
    * 新增
    *
    * @param ${table.entityPath}
    * @return
    */
    @ApiOperation("新增")
    @RequestMapping(method = RequestMethod.POST)
    public SimpleMessage<${entity}> save(@RequestBody ${entity} ${table.entityPath}){
        boolean save = ${table.entityPath}Service.save(${table.entityPath});
        if(save){
            return SimpleMessage.info("添加成功");
        }else{
            return SimpleMessage.fail("添加失败");
        }
    }

    /**
    * 修改
    *
    * @param ${table.entityPath}
    * @return
    */
    @ApiOperation("修改")
    @RequestMapping(method = RequestMethod.PUT)
    public SimpleMessage<${entity}> update(@RequestBody ${entity} ${table.entityPath}) {
        boolean save = ${table.entityPath}Service.updateById(${table.entityPath});
        if (save) {
            return SimpleMessage.info("修改成功");
        } else {
            return SimpleMessage.fail("修改失败");
        }
    }

    /**
    * 删除
    *
    * @param id 主键id
    * @return
    */
    @ApiOperation("删除")
    @RequestMapping(value = "/{id}" , method = RequestMethod.DELETE)
    public SimpleMessage delete(@PathVariable long id) {
        return ${table.entityPath}Service.deleteById(id);
    }

    /**
    * 查询详情
    *
    * @param id 主键id
    * @return
    */
    @ApiOperation("查询详情")
    @RequestMapping(value = "/{id}" , method = RequestMethod.GET)
    public SimpleMessage<${entity}> findOne(@PathVariable long id) {
        return SimpleMessage.info(${table.entityPath}Service.getById(id));
    }

    /**
    * 分页查询
    *
    * @param pageQuery 分页查询
    * @return
    */
    @ApiOperation("分页查询")
    @RequestMapping(method = RequestMethod.GET)
    public SimpleMessage queryByPage(PageQuery pageQuery) {
        return ${table.entityPath}Service.queryByPage(pageQuery);
    }
}
</#if>
